var app = getApp();
var https = "https://www.moreclub.cn/";
var htp = 'http://more-image.oss-cn-beijing.aliyuncs.com/pinzuominiapp/pinzuoall_bg_';
var http2 = 'http://59.110.53.149:8088/'
var city;
var page = 0;
var add0 = function (m) {
  return m < 10 ? '0' + m : m
}
var time = function (timestamp) {
  var time = new Date(timestamp);
  // var y = time.getFullYear();
  var m = time.getMonth() + 1;
  var d = time.getDate();
  var h = time.getHours();
  var mm = time.getMinutes();
  // var s = time.getSeconds();
  // return y + '-' + add0(m) + '-' + add0(d) + ' ' + add0(h) + ':' + add0(mm) + ':' + add0(s);
  return add0(m) + '月' + add0(d) + '日' + ' ' + add0(h) + ':' + add0(mm)
}

var getList = function(that){
  wx.request({
    url: https + 'v2/signinter/open/cityInters?city='+city ,
    data:{
      pn:page,
      ps:5
    },
    success: function (res) {
      console.log(res)
      var datalist = res.data.data
      let dataArr = []

      for (var i = 0; i < datalist.length; i++) {

        var p = datalist[i].userThumb;
        var name = datalist[i].nickName;
        // var day = datalist[i].day;
        var age = datalist[i].age;
        var gender = datalist[i].gender;
        var merchantName = datalist[i].merchantName;
        var mid = datalist[i].mid;
        var uid1 = datalist[i].uid;
        var cont = datalist[i].content;
        var gift = datalist[i].gift;
        var sid = datalist[i].sid;
        var type1 = datalist[i].type;

        if (datalist[0].timestamp.toString().length == 10) {
          var timestamp = datalist[i].timestamp * 1000;
        } else {
          var timestamp = datalist[i].timestamp;
        }


        if (type1 == 5 || type1 == null) {
          var txt = 0;
        }
        if (type1 == 3) {
          var txt = 1;
        }
        if (type1 == 6) {
          var txt = 2;
        }
        if (type1 == 4) {
          var txt = 3;
        }
        if (type1 == 1) {
          var txt = 4;
        }
        if (type1 == 2) {
          var txt = 5;
        }

        time(timestamp)

        var dataTime = time(timestamp)


        let obj = {}
        obj.height = 0,
          obj.pic = p || null,
          obj.name = name,
          obj.age = age,
          obj.uid1 = uid1,
          obj.gender = gender,
          obj.mid = mid,
          obj.gift = gift,
          obj.txt = txt,
          obj.sid = sid,
          obj.content = cont,
          obj.merchantName = merchantName,
          obj.dataTime = dataTime,
          dataArr.push(obj)

      }
      if (dataArr != null) {
        //that.data.totallist.concat(dataArr);

        var oldlist = that.data.totallist;
        for (var i = 0; i < dataArr.length; i++) {
          oldlist.push(dataArr[i])
        }
      }

      that.setData({
        dataArr: dataArr,
        totallist: oldlist
      })
    }
  })
}

Page({
  data: {
    totallist: [],
      src: [htp + '6_o.png', htp + '4_y.png', htp + '3_r.png', htp + '2_p.png', htp + '1_g.png', htp + '5_b.png'],
      border: ['1px solid #f8a52c', '1px solid #f6e33e', '1px solid #ef4444', '1px solid #8c32d6', '1px solid #23c114', '1px solid #08cee1'],
      icon: ['pinzuo_6_pgz_black@2x.png', 'pinzuo_4_llt_black@2x.png', 'pinzuo_3_wyx_black@2x.png', 'pinzuo_2_qhd_black@2x.png', 'pinzuo_1_bgm_black@2x.png', 'pinzuo_5_bsh_black@2x.png'],
      icon2: ['buyuadrink_white@2x.png', 'cocktail_white@2x.png', 'beerbrew_white@2x.png', 'wine_white@2x.png', 'whiskey_white@2x.png', 'importbeer_white@2x.png', 'champagne_white@2x.png', 'brandy_white@2x.png', 'saki_white@2x.png'],
      tent: ['拼个座', '聊撩天', '玩游戏', '求回答', '帮个忙', '憋说话'],
      cont: ['', '鸡尾酒', '精酿啤酒', '葡萄酒', '威士忌', '进口啤酒', '香槟', '白兰地', '清酒'],
      holder: ['一个人喝酒超级无聊，想找好玩朋友拼个座，带我飞。', '聊音乐，电影，酒...认识有趣的你！', '急！玩游戏缺人，求旁边的帅哥靓女加入~', '城市小白，求土著支招好吃的好玩的去处！', '遇见生活小难题，求大神支招！', '开车堵，上班老板不酷，回家生活不酷，憋着难受，这里说点酷的！']

  },
  onReady: function () {
    var that = this;
    city = wx.getStorageSync('city')
    if (city == '' || !city|| typeof (city) == "undefined") {
      city = 'cd'
    }

    console.log('city', city)
    page = 0;
    getList(that);
  },
  onLoad:function(){
   
  },

  onReachBottom: function () {
    // 页面上拉触底事件的处理函数
    var that = this;
    if (that.data.dataArr != null && that.data.dataArr.length != 0) {
      page += 1;
      getList(that);
    } else {
      wx.showToast({
        title: '已加载完成',
        duration: 1000
      })
    }
  },


 
})